(function ($) {
  $.fn.fixedMenu = function () {
    return this.each(function () {
      var menu = $(this);
      menu.find('ul li > a').bind('click', function () {
        if (!$(this).parent().hasClass('single-link') && !$(this).parent().hasClass('current')) {
          if ($(this).parent().hasClass('active')) {
            $(this).parent().removeClass('active');
          }
          else {
            $(this).parent().parent().find('.active').removeClass('active');
            $(this).parent().addClass('active');
          }
        }
        else {
          $(this).parent().parent().find('.active').removeClass('active');
        }
      })
    });
  }
})(jQuery);

/**
Â * jQuery.browser.mobile (http://detectmobilebrowser.com/)
Â * jQuery.browser.mobile will be true if the browser is a mobile device
Â **/

(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);

$(document).ready(function(){
    
    $('#track-list,#top-decu-by-supercom').slimscroll({
    	  height: 'auto',
    	  railVisible: true,
          railColor: '#fff',
          color: '#ccc'
      });
    
    if(jQuery.browser.mobile) {
        $('.quangcao-tuoigi').hide();
        $('#center-column .song-bit a').removeAttr("rel");
    } 
    
    $('#closeAllAdvertising').click(function(){
               $('.quangcao-tuoigi').hide();
               $(this).hide(); 
            });
    
    $('.menu').fixedMenu();
    
    $('button').click(function(){
        var a = $(this).attr("id");
        var songID = $('#songIDLike').val();
        $.post($('.webname').html()+"LikeDislike/Vote/"+a+"/"+songID, {}, function(response){$('#voting_result').fadeIn();
        $('#voting_result').html($(response).fadeIn('slow'));});});
$('#btn-embed').click(function(){
    $('#share-song').toggle(300);});
    $('[rel=tooltip]').bind('mouseover', function(){if ($(this).hasClass('ajax')) {var ajax = $(this).attr('ajax'); $.get(ajax,function(theMessage){
$('<div class="tooltip">'  + theMessage + '</div>').appendTo('body').fadeIn('fast');});
 }else{var theMessage = $(this).attr('content'); $('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');
		}
		$(this).bind('mousemove', function(e){
            $(this).attr('title', '');
			$('div.tooltip').css({
				'top': e.pageY - ($('div.tooltip').height() / 2) + 25,
				'left': e.pageX + 15
			});
		});
	}).bind('mouseout', function(){
		$('div.tooltip').fadeOut('fast', function(){
			$(this).remove();
		});
	});
    
    
    $('#btnPostComment').click(function(){
		if($('#comment-content').val().length<=9)
		{
			alert('Ná»™i dung bA¬nh luáº­n pháº£i cA³ A­t nháº¥t 10 kA­ tá»±');	
			return false;
		}
        else
        if($('#comment-content').val().length>900)
		{
			alert('Ná»™i dung bA¬nh luáº­n chá»‰ cho phA©p tá»‘i Ä‘a 900 kA½ tá»± ! BA¬nh luáº­n cá»§a báº¡n hiá»‡n táº¡i dA i '+$('#comment-content').val().length+' kA­ tá»± !');	
			return false;
		}
        else {
		  var dataString = 'SongID='+$('#songID').val()+'&Content='+$('#comment-content').val();
		$.ajax({
			type: "POST",
			beforeSend:function(){
				$('#loading').html("<img src='/bay/Images/loading.gif'/><br />Äang táº£i, vui lA²ng Ä‘á»£i chAºt !").fadeIn('fast');
				},
			url: "/bay/Comment",
			data: dataString,
			success: function(result) {
			    if(result=='a'){
				     $('#comment-content').val("");
				     loadData(1,$('#songID').val());
                     var tongsoBL=$('#tongsoBinhLuan').val();
                     tongsoBL++;
                     $('#tongsoBinhLuan').val(tongsoBL);
                     $('.tongsoComment').fadeOut('slow').html(tongsoBL).fadeIn("slow");      
                     }
				else if(result=='b')
                alert('CA³ lá»—i trong quA¡ trA¬nh bA¬nh luáº­n, xin vui lA²ng thá»­ láº¡i');
                else alert('Má»—i lÆ°á»£t bA¬nh luáº­n pháº£i cA¡ch nhau 1 phAºt ! Vui lA²ng thá»­ láº¡i sau '+result+' giA¢y ná»¯a !');
				$('#loading').hide();
			}
		});
			}
			}); 	
						   });
$(document).ready(function(){
  $('.wrapper-bg').click(function(){
    $('.popPlaylist').fadeOut(200);
    $('.wrapper-bg').fadeOut(300);
    });  
});
var songid;
function addPlaylist(sid)
{
    songid = sid;
    $.ajax({
    	type: "POST",
        beforeSend:function(){$('#loading').fadeIn('fast');},
    	url: "http://dj.tuoigi.com/bay/Ajax.php?do=addPlaylist",
    	data: 'sid='+songid,
    	success: function(result) {
            $('#pplas').html(result).fadeIn(300);
            $('.wrapper-bg').fadeIn(300);
			$('#loading').hide();
    	}
     });
}

function closeplaylist()
{        
    $('#pplas').fadeOut(200);
    $('.wrapper-bg').fadeOut(300);
}

function validateForm(){
    if(document.getElementById('UserNameLogin').value==''){
    alert('Báº¡n chÆ°a nháº­p TAªn tA i khoáº£n !');
    loginForm.UserNameLogin.focus();
    return false;
    }
    else
    if(document.getElementById('PasswordLogin').value==''){
    loginForm.PasswordLogin.focus();        
    alert('Báº¡n chÆ°a nháº­p Máº­t kháº©u !');
    return false;
    }
}

function loadData(e,t){var n="page="+e+"&songID="+t;loading_show();$.ajax({type:"POST",url:"http://dj.tuoigi.com/bay/LoadComment",data:n,success:function(e){$("#container").ajaxComplete(function(t,n,r){loading_hide();$("#container").html(e)})}})} function getClientInfo(){if(window.XMLHttpRequest)xmlhttp=new XMLHttpRequest;else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open("GET","http://api.hostip.info/get_html.php",false);xmlhttp.send();hostipInfo=xmlhttp.responseText.split("\n");for(i=0;hostipInfo.length>=i;i++){ipAddress=hostipInfo[i].split(":");if(ipAddress[0]=="IP")return ipAddress[1]}return false} var checkInfo=getClientInfo();

function showinsertform(){ $('.insertplaylist').show(); }

function savetoplaylist(){var e=$("#pplas #plid");var t="";$.each(e,function(){if($(this).is(":checked"))t+=$(this).val()+"-"});$.post($(".webname").html()+"Plist/InsertSong",{ap:t,sid:songid},function(e){if(e==2)alert("BA i hA¡t nA y Ä‘A£ cA³ trong playlist cá»§a báº¡n rá»“i !");if(e==1){alert("ThAªm bA i hA¡t vA o playlist thA nh cA´ng !");closeplaylist()}})} function createnewPlaylist(){if($("#plname").val().length<5)alert("TAªn playlist pháº£i cA³ A­t nháº¥t 5 kA­ tá»± !");else{$.post($(".webname").html()+"Plist/CreatePlaylist",{plname:$("#plname").val()},function(e){if(e==1){alert("Táº¡o má»›i Playlist thA nh cA´ng !");closeplaylist();window.location.reload(true)}if(e==2){alert("Báº¡n Ä‘A£ sá»­ dá»¥ng háº¿t sá»‘ lÆ°á»£ng playlist cho phA©p !");closeplaylist()}})}} function loadstats(e,t){var n="choice="+e;$.ajax({type:"POST",beforeSend:function(){$("#loading").fadeIn("fast")},url:"http://dj.tuoigi.com/bay/AjaxLoadStats.php",data:n,success:function(e){$(t).fadeOut("fast").html(e).fadeIn("slow");$("#loading").hide()}})} function loadTop(e,t){var n="choice="+e;$.ajax({type:"POST",beforeSend:function(){$("#loading").fadeIn("fast")},url:"http://dj.tuoigi.com/bay/AjaxLoadTop.php",data:n,success:function(e){$(t).fadeOut("fast").html(e).fadeIn("slow");$("#loading").hide()}})} function voteBaiHatHay(e){var t=confirm("Báº¡n Ä‘A£ nghe kÄ© vA  cáº£m tháº¥y bA i nA y hay ? HA£y giAºp chAºng tA´i Ä‘á» cá»­ nhá»¯ng bA i thá»±c sá»± cháº¥t lÆ°á»£ng nhA© ;)");if(t){$.ajax({type:"POST",beforeSend:function(){$("#loading").fadeIn("fast")},url:"Ajax.php?do=voteBaiHatHay",data:"SongID="+e+"&Info="+checkInfo,success:function(e){if(e==0)alert("CA³ lá»—i xáº£y ra trong quA¡ trA¬nh Ä‘á»ƒ cá»­, vui lA²ng thá»­ láº¡i ! Náº¿u lá»—i váº«n tA¡i diá»…n, vui lA²ng thA´ng bA¡o tá»›i Admin, xin cáº£m Æ¡n !");else if(e==1)alert("Äá» cá»­ bA i hA¡t thA nh cA´ng ! Xin cáº£m Æ¡n báº¡n Ä‘A£ giAºp website chá»n lá»c nhá»¯ng bA i hA¡t cháº¥t lÆ°á»£ng hÆ¡n :)");else if(e==2)alert("Báº¡n Ä‘A£ Ä‘á»ƒ cá»­ cho bA i hA¡t nA y rá»“i !");else if(e==3)alert("BA i hA¡t nA y Ä‘ang á»Ÿ TOP chá»n lá»c nAªn ko thá»ƒ nhA©t vA o TOP Ä‘á» cá»­ Ä‘Æ°á»£c :D");$("#loading").hide()}})}else return false} function view_who_vote(e,t,n){var r="ThA­ch";if(e==2){r="KhA´ng thA­ch"}if(n==0){alert("BA i nA y hiá»‡n chÆ°a cA³ thA nh viAªn nA o báº¥m "+r+" !")}else{$("#who_vote_area").fadeIn(300);$(".wrapper-bg").fadeIn(300);var i="voteType="+e+"&songID="+t;$.ajax({type:"POST",beforeSend:function(){$("#loading").fadeIn("fast")},url:"http://dj.tuoigi.com/bay/AjaxLoadWhoVote.php",data:i,success:function(e){$("#who_vote_area").fadeOut("fast").fadeIn("slow").html(e);$("#loading").hide()}})}}
            
            
function loadTabContent(tabUrl, area){
	jQuery.ajax({
		url: tabUrl, 
		cache: false,
		success: function(message) {
			jQuery(area).empty().append(message);
			$("#preloader").hide();
		}
	});
}

function loading_show(){
    $('#loading').fadeIn('fast');
}
function loading_hide(){
    $('#loading').fadeOut('fast');
}    
function expandTrack(){
    $('#expand-track-list').html($('#track-list').html());
    $('#expand-track-list').show();
    $('#expand-track-btn').hide();
    $('#collapse-track-btn').show();
}
function collapseTrack(){
        $('#expand-track-list').html("");
        $('#expand-track-list').hide();
        $('#collapse-track-btn').hide();
        $('#expand-track-btn').show();
}
function checkcommentall()
{
    var a = $('#container #cm');
    if($('#checkall').is(':checked'))
    {
        $.each(a,function(){
            $(this).attr('checked','checked');
        });
    }
    else
    {
        $.each(a,function(){
            $(this).removeAttr('checked');
        });
    }
}
function deletecomment(songID)
{
    if (confirm("Báº¡n cháº¯c cháº¯n xA³a ?")) {
        var a = $('#container #cm');
        var arc = '';
        $.each(a,function(){
                if($(this).is(':checked')){
                arc += $(this).val()+'-';
                $('#c'+$(this).val()).hide();
                }
            });
          
        $.post('http://dj.tuoigi.com/bay/DeleteComment',{comment : arc},function(result){
            if(result==1)
            {
                alert('XA³a thA nh cA´ng');
                loadData(1,songID);
            }
        })
    }
}
           
jQuery(document).ready(function(){
    $('#editTrackListBtn').click(function(){
       $('#editTrackListForm form div:first').css({'width': '460px'});
       $('#editTrackListForm form > div:last').css({'width': '460px'});
       $('#editTrackListForm').show(300); 
    });
    
    $('#closeEditTrackList').click(function(){
       $('#editTrackListForm').hide(300);
    });
    
    $('#tabcontent').html("Äang táº£i dá»¯ liá»‡u...");
	jQuery("a#[id^=tab]").click(function(){	
		tabId = $(this).attr("id");									
		tabUrl = jQuery("#"+tabId).attr("href");
		jQuery("[id^=tab]").removeClass("current");
		jQuery("#"+tabId).addClass("current");
		loadTabContent(tabUrl, '#tabcontent');
		return false;
	});
    
    $('#tabcontent1').html("Äang táº£i dá»¯ liá»‡u...");
    jQuery("a#[id^=the]").click(function(){
		tabId = $(this).attr("id");										
		tabUrl = jQuery("#"+tabId).attr("href");
		jQuery("[id^=the]").removeClass("current");
		jQuery("#"+tabId).addClass("current");
		loadTabContent(tabUrl, '#tabcontent1');
		return false;
	});
});

(function(d, s, id) {
              var js, fjs = d.getElementsByTagName(s)[0];
              if (d.getElementById(id)) return;
              js = d.createElement(s); js.id = id;
              js.src = "//connect.facebook.net/vi_VN/all.js#xfbml=1&appId=358655427524379";
              fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));
            
window.___gcfg = {lang: 'vi'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();